color10 2.2.1
color10.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2026 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
31// ----------------------------------------------------------------------------
32
33#ifndef COLOR10_H
34#define COLOR10_H
35
40#ifdef PREINIT_SUPPORTED
41#include "preinit.h"
42#endif
43
44#ifdef MikroCCoreVersion
45 #if MikroCCoreVersion >= 1
46 #include "delays.h"
47 #endif
48#endif
49
50#include "drv_digital_out.h"
51#include "drv_digital_in.h"
52#include "drv_i2c_master.h"
53
54// -------------------------------------------------------------- PUBLIC MACROS
59
64#define COLOR10_MAP_MIKROBUS( cfg, mikrobus ) \
65 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
66 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
67
68
73#define COLOR10_RETVAL uint8_t
74
75#define COLOR10_OK 0x00
76#define COLOR10_INIT_ERROR 0xFF
78
79#define COLOR10_SLAVE_ADDR 0x10
80
81#define COLOR10_CMD_REG_CFG 0x00
82#define COLOR10_CMD_REG_C 0x04
83#define COLOR10_CMD_REG_R 0x05
84#define COLOR10_CMD_REG_G 0x06
85#define COLOR10_CMD_REG_B 0x07
86#define COLOR10_CMD_REG_IR 0x08
87#define COLOR10_CMD_REG_ID 0x0C
88
89#define COLOR10_DEVICE_ID 0x28
90
91#define COLOR10_COLOR_ORANGE 0x11
92#define COLOR10_COLOR_RED 0x22
93#define COLOR10_COLOR_PINK 0x33
94#define COLOR10_COLOR_PURPLE 0x44
95#define COLOR10_COLOR_BLUE 0x55
96#define COLOR10_COLOR_CYAN 0x66
97#define COLOR10_COLOR_GREEN 0x77
98#define COLOR10_COLOR_YELLOW 0x88
99#define COLOR10_COLOR_OTHER 0x99
100
101#define COLOR10_CFG_HIGH_DYNAMIC_RANGE_1_3 0x0040
102#define COLOR10_CFG_HIGH_DYNAMIC_RANGE_1 0x0000
103#define COLOR10_CFG_INTEGRATION_TIME_SETT_50_MS 0x0000
104#define COLOR10_CFG_INTEGRATION_TIME_SETT_100_MS 0x0010
105#define COLOR10_CFG_INTEGRATION_TIME_SETT_200_MS 0x0020
106#define COLOR10_CFG_INTEGRATION_TIME_SETT_400_MS 0x0030
107#define COLOR10_CFG_AUTO_MODE 0x0000
108#define COLOR10_CFG_FORCE_MODE 0x0008
109#define COLOR10_CFG_TRIGGER_NO 0x0000
110#define COLOR10_CFG_TRIGGER_ONE_TIME 0x0004
111#define COLOR10_CFG_POWER_ON 0x0000
112#define COLOR10_CFG_SHUT_DOWN 0x8001
113#define COLOR10_CFG_POWER_ON_G_C_IR 0x4000
114#define COLOR10_CFG_GAIN_1_X1 0x0000
115#define COLOR10_CFG_GAIN_1_X2 0x1000
116#define COLOR10_CFG_GAIN_1_X4 0x2000
117#define COLOR10_CFG_GAIN_2_X1_2 0x0C00
118#define COLOR10_CFG_GAIN_2_X1 0x0000
119#define COLOR10_CFG_GAIN_2_X2 0x0400
120#define COLOR10_CFG_GAIN_2_X4 0x0800
121 // End group macro
123// --------------------------------------------------------------- PUBLIC TYPES
128
132typedef struct
133{
134
135 // Modules
136
137 i2c_master_t i2c;
138
139 // ctx variable
140
142
143} color10_t;
144
148typedef struct
149{
150 // Communication gpio pins
151
152 pin_name_t scl;
153 pin_name_t sda;
154
155 // static variable
156
157 uint32_t i2c_speed;
158 uint8_t i2c_address;
159
161 // End types group
163// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
164
169
170#ifdef __cplusplus
171extern "C"{
172#endif
173
183
193
204void color10_generic_write ( color10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
205
216uint16_t color10_generic_read ( color10_t *ctx, uint8_t cmd_addr );
217
226void color10_config ( color10_t *ctx, uint16_t cfg_data );
227
237uint8_t color10_get_id ( color10_t *ctx );
238
249float color10_read_color_ratio ( color10_t *ctx, uint8_t color_cmd_reg );
250
261
271uint8_t color10_get_color ( float color_value );
272
273
274#ifdef __cplusplus
275}
276#endif
277#endif // _COLOR10_H_
278 // End public_function group
281
282// ------------------------------------------------------------------------- END
#define COLOR10_RETVAL
Definition color10.h:73
void color10_cfg_setup(color10_cfg_t *cfg)
Config Object Initialization function.
COLOR10_RETVAL color10_init(color10_t *ctx, color10_cfg_t *cfg)
Initialization function.
uint8_t color10_get_color(float color_value)
Color retrieval function.
uint8_t color10_get_id(color10_t *ctx)
ID retrieval function.
uint16_t color10_generic_read(color10_t *ctx, uint8_t cmd_addr)
Generic read function.
void color10_config(color10_t *ctx, uint16_t cfg_data)
Configuration function.
void color10_generic_write(color10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
float color10_read_color_ratio(color10_t *ctx, uint8_t color_cmd_reg)
Color ratio function.
float color10_get_color_value(color10_t *ctx)
Color value function.
Click configuration structure definition.
Definition color10.h:149
uint32_t i2c_speed
Definition color10.h:157
pin_name_t scl
Definition color10.h:152
pin_name_t sda
Definition color10.h:153
uint8_t i2c_address
Definition color10.h:158
Click ctx object definition.
Definition color10.h:133
i2c_master_t i2c
Definition color10.h:137
uint8_t slave_address
Definition color10.h:141